home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / laptop-mode-tools / modules / wireless-ipw-power < prev    next >
Encoding:
Text File  |  2012-05-20  |  4.8 KB  |  156 lines

  1. #! /bin/sh
  2. # Laptop mode tools module: power saving for IPW3945, IPW2200 and IPW2100 using
  3. #                           the Intel ipw drivers.
  4. #
  5. #
  6. # This script relies upon the name of the driver.
  7. #
  8. # Original source: http://ubuntuforums.org/showthread.php?t=419772
  9.  
  10. if [ x$CONTROL_IPW_POWER = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_IPW_POWER = xauto ]; then
  11.  
  12.     # Provide defaults for config file settings
  13.     [ "$IPW3945_AC_POWER" ]   || IPW3945_AC_POWER=6
  14.     [ "$IPW3945_BATT_POWER" ] || IPW3945_BATT_POWER=7
  15.     [ "$IPW2100_AC_POWER" ]   || IPW3945_AC_POWER=0
  16.     [ "$IPW2100_BATT_POWER" ] || IPW3945_BATT_POWER=5
  17.  
  18.     I3945_DRIVERNAME=ipw3945
  19.     I2200_DRIVERNAME=ipw2200
  20.     I2100_DRIVERNAME=ipw2100
  21.  
  22.     # find executables
  23.     if [ -x /sbin/iwpriv ] ; then
  24.         IWPRIV=/sbin/iwpriv
  25.     elif [ -x /usr/sbin/iwpriv ] ; then
  26.         IWPRIV=/usr/sbin/iwpriv
  27.     else
  28.         log "VERBOSE" "iwpriv is not installed"
  29.     fi
  30.     if [ -x /sbin/iwconfig ] ; then
  31.         IWCONFIG=/sbin/iwconfig
  32.     elif [ -x /usr/sbin/iwconfig ] ; then
  33.         IWCONFIG=/usr/sbin/iwconfig
  34.     else
  35.         log "VERBOSE" "iwconfig is not installed"
  36.     fi
  37.  
  38.     SET_I3945_AC_PARMS="set_power $IPW3945_AC_POWER"
  39.     SET_I3945_BAT_PARMS="set_power $IPW3945_BATT_POWER"
  40.  
  41.     SET_I2200_AC_PARMS="power off"
  42.     SET_I2200_BAT_PARMS="power on"
  43.  
  44.     # Note the fact that we're setting "power on" on both AC and battery.
  45.     # This is due to the fact that the second statement will have no effect
  46.     # if we turn power management off completely, and some laptops will
  47.     # reportedly get very hot if you turn off power management on the
  48.     # IPW2100.
  49.     SET_I2100_AC_PARMS_1="power on"
  50.     SET_I2100_BAT_PARMS_1="power on"
  51.     SET_I2100_AC_PARMS_2="set_power $IPW2100_AC_POWER"
  52.     SET_I2100_BAT_PARMS_2="set_power $IPW2100_BATT_POWER"
  53.  
  54.  
  55.     #
  56.     # Find all the wireless devices using the supplied driver names.
  57.     # Place the interface names on the list WIFI_IFNAMES.
  58.     #
  59.     findWifiIfsByDriver() {
  60.         local DEVICE;
  61.         local LINK_TARGET;
  62.                 local ENABLED;
  63.         WIFI_IFNAMES=""
  64.  
  65.         for DEVICE in /sys/class/net/*; do
  66.             if [ -d $DEVICE/wireless -a -h $DEVICE/device/driver ]; then
  67.                 # See if the driver for $DEVICE matches the supplied one by checking the link to
  68.                 # the driver.
  69.                 LINK_TARGET=`readlink $DEVICE/device/driver`
  70.                 LINK_TARGET=${LINK_TARGET##*/}
  71.                                 ENABLED=`cat $DEVICE/device/enable`
  72.  
  73.                 if [ $ENABLED -eq 1 -a "$LINK_TARGET" = "$1" ]; then
  74.                     # add the interface name to the list
  75.                             WIFI_IFNAMES="$WIFI_IFNAMES ${DEVICE##*/}"
  76.                                 else
  77.                                         log "VERBOSE" "$DEVICE doesn't seem to be enabled. Radio Switched off?";
  78.                 fi
  79.                         else
  80.                                 # LP: #369113
  81.                                 # Kernel's 2.6.29 and above have been reported to be missing
  82.                                 # the $DEVICE/wireless folder.
  83.                                 dev=`basename $DEVICE`
  84.  
  85.                 # Inverting return values, we get "0" for wireless device, 
  86.                 # and "1" for non-wireless device.
  87.                 ($IWCONFIG $dev 2>&1 | grep -q "no wireless extensions.") && ret=1 || ret=0
  88.                                 if [ "$ret" = "0" ]; then
  89.                     # add the interface name to the list
  90.                             WIFI_IFNAMES="$WIFI_IFNAMES ${DEVICE##*/}"
  91.                                 fi
  92.             fi
  93.         done
  94.     }
  95.  
  96.  
  97.     #
  98.     # Set all the adaptors using the supplied driver into the supplied
  99.     # power saving mode
  100.     #
  101.     # $1 - driver name
  102.     # $2 - power command
  103.     # $3 - power command arguments
  104.     #
  105.     setWifiPwrSave () {
  106.         local DEVICE;
  107.         findWifiIfsByDriver $1;
  108.  
  109.         for DEVICE in $WIFI_IFNAMES; do
  110.             log "VERBOSE" "Wireless power saving: $2 $DEVICE $3"
  111.             $2 $DEVICE $3
  112.         done
  113.     }
  114.  
  115.     intel3945_BatPwrSave () {
  116.         setWifiPwrSave "$I3945_DRIVERNAME" "$IWPRIV" "$SET_I3945_BAT_PARMS"
  117.     }
  118.  
  119.     intel3945_AcPwrSave () {
  120.         setWifiPwrSave "$I3945_DRIVERNAME" "$IWPRIV" "$SET_I3945_AC_PARMS"
  121.     }
  122.  
  123.     intel2200_BatPwrSave () {
  124.         setWifiPwrSave "$I2200_DRIVERNAME" "$IWCONFIG" "$SET_I2200_BAT_PARMS"
  125.     }
  126.  
  127.     intel2200_AcPwrSave () {
  128.         setWifiPwrSave "$I2200_DRIVERNAME" "$IWCONFIG" "$SET_I2200_AC_PARMS"
  129.     }
  130.  
  131.     intel2100_BatPwrSave () {
  132.         setWifiPwrSave "$I2100_DRIVERNAME" "$IWCONFIG" "$SET_I2100_BAT_PARMS_1"
  133.         setWifiPwrSave "$I2100_DRIVERNAME" "$IWPRIV" "$SET_I2100_BAT_PARMS_2"
  134.     }
  135.  
  136.     intel2100_AcPwrSave () {
  137.         setWifiPwrSave "$I2100_DRIVERNAME" "$IWCONFIG" "$SET_I2100_AC_PARMS_1"
  138.         setWifiPwrSave "$I2100_DRIVERNAME" "$IWPRIV" "$SET_I2100_BAT_PARMS_2"
  139.     }
  140.  
  141.  
  142.     if [ $ON_AC -eq 1 ] ; then
  143.         [ -d /sys/module/$I3945_DRIVERNAME ] && intel3945_AcPwrSave
  144.         [ -d /sys/module/$I2200_DRIVERNAME ] && intel2200_AcPwrSave
  145.         [ -d /sys/module/$I2100_DRIVERNAME ] && intel2100_AcPwrSave
  146.     else
  147.         [ -d /sys/module/$I3945_DRIVERNAME ] && intel3945_BatPwrSave
  148.         [ -d /sys/module/$I2200_DRIVERNAME ] && intel2200_BatPwrSave
  149.         [ -d /sys/module/$I2100_DRIVERNAME ] && intel2100_BatPwrSave
  150.     fi
  151. else
  152.     log "VERBOSE" "Intel IPW Wireless power setting is disabled."
  153. fi
  154.  
  155.